package com.loan.market.ui

import android.os.Bundle
import android.view.View
import android.webkit.WebChromeClient
import android.webkit.WebView
import com.loan.market.base.BaseBindingActivity
import com.loan.market.databinding.ActivityWebBinding

class WebActivity : BaseBindingActivity<ActivityWebBinding>() {

    override fun getViewBinding(): ActivityWebBinding {
        return ActivityWebBinding.inflate(layoutInflater)
    }

    private val url by lazy { intent.getStringExtra("url") ?: "" }
    private val title by lazy { intent.getStringExtra("title") }

    override fun initUi(savedInstanceState: Bundle?) {
        binding.titleBar.setTitle(title)
        binding.webView.loadUrl(url)
    }

    override fun initEvent() {
        binding.webView.webChromeClient = object : WebChromeClient() {
            override fun onProgressChanged(view: WebView?, newProgress: Int) {
                if (newProgress == 100) {
                    binding.progress.visibility = View.GONE
                } else {
                    binding.progress.visibility = View.VISIBLE
                    binding.progress.progress = newProgress
                }
                super.onProgressChanged(view, newProgress)
            }
        }
    }

    override fun initData() {

    }

    override fun back() {
        setResult(RESULT_OK)
        finish()
    }

}